package edu.yctc.manage.service.impl;

import edu.yctc.manage.dao.SdeptDAO;
import edu.yctc.manage.entity.PageDO;
import edu.yctc.manage.entity.SdeptDO;
import edu.yctc.manage.service.SdeptService;
import edu.yctc.manage.utils.PageQuery;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName SdeptServiceImpl
 * @Description TODO
 * @Author zyj
 * @Date 2021/3/30 10:56
 * @Version 1.0
 **/
@Service
public class SdeptServiceImpl implements SdeptService {

    @Resource
    private SdeptDAO sdeptDAO;

    @Override
    public List<SdeptDO> getSdeptDOList() {
        return sdeptDAO.getAll();
    }

    @Override public PageDO getSdepts(PageQuery pageQuery) {
        List<SdeptDO> sdeptDOS = sdeptDAO.selectList(pageQuery);
        int total = sdeptDAO.getTotal();
        return new PageDO(total, pageQuery.getLimit(), pageQuery.getPage(), sdeptDOS);
    }

    @Override public int save(String name) {
        SdeptDO sdeptDO = new SdeptDO();
        sdeptDO.setName(name);
        return sdeptDAO.insert(sdeptDO);
    }

    @Override public int delete(Long[] ids) {
        return sdeptDAO.deleteBatchIds(Arrays.asList(ids));
    }

    @Override public int update(SdeptDO sdeptDO) {
        return sdeptDAO.update(sdeptDO);
    }
}
    